package cn.signalpha.common.wechat.handler;

import cn.signalpha.modules.base.service.WxReplyRuleService;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Binary Wang(https://github.com/binarywang)
 */
@Component
@AllArgsConstructor
public class MenuHandler extends AbstractHandler {

	private final WxReplyRuleService wxReplyRuleService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService weixinService,
                                    WxSessionManager sessionManager) {
		if (WxConsts.EventType.VIEW.equals(wxMessage.getEvent())) {
			return null;
		}
//		logger.info("菜单事件：" + wxMessage.getEventKey());
		wxReplyRuleService.tryAutoReply(wxMessage.getFromUser(), wxMessage.getEventKey());
		return null;
    }

}
